from google.appengine.ext import webapp
from DataClass.WebsiteRec import WebsiteRec
from DataClass.SiteUser import SiteUser
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from AdminBase import AdminBase

import os
import cgi

class RemoveUserFromSiteHandler(AdminBase):
    def GetTemplateValuesDict(self, template_values, user):
        querystring=cgi.FieldStorage()

        admin = querystring.getvalue('admin')
        sitename = querystring.getvalue('sitename')
        isadmin = (admin == '1')
        email = querystring.getvalue('email')
        
        Website = WebsiteRec.GetWebsiteBySiteName(self.request.get('sitename'))
        
        if Website:
            if email:
                if isadmin:
                    if email in Website.adminuseremails:
                        Website.adminuseremails.remove(email)
                else:
                    if email in Website.useremails:
                        Website.useremails.remove(email)
                Website.put()

    def DoPost(self, user):
        self.redirect('/editwebsites')

    def GetRedirect(self):
        return '/editwebsites';